package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.core.WeixinPayConfigDao;
import com.tbit.uqbike.client.pojo.WeixinConfig;
import com.tbit.uqbike.client.pojo.WeixinPayConfig;
import com.tbit.uqbike.client.service.CacheService;
import com.tbit.uqbike.client.service.WeixinPayConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("weixinPayConfigService")
public class WeixinPayConfigServiceImpl implements WeixinPayConfigService {
    @Autowired
    private WeixinPayConfigDao weixinPayConfigDao;
    @Autowired
    private CacheService cacheService;

    @Override
    public WeixinPayConfig getByAccountId(Integer accountId, Integer type) {
        return cacheService.getWxPay(accountId, type);
		/*Map<String,Object> params=new HashMap<String,Object>();
		params.put("accountId", accountId);
		params.put("type", type);
		
		return weixinPayConfigDao.getByAccountId(params);*/
    }


    @Override
    public void edit(WeixinPayConfig weixinPayConfig) {
        WeixinPayConfig weixinPayConfigDB = getByAccountId(weixinPayConfig.getAccountId(), weixinPayConfig.getType());
        if (weixinPayConfigDB != null) {
            if (weixinPayConfig.getRemark() == null) {
                weixinPayConfig.setRemark(weixinPayConfigDB.getRemark());
            }
            weixinPayConfigDao.edit(weixinPayConfig);
        } else {
            weixinPayConfigDao.add(weixinPayConfig);
        }
    }

    @Override
    public WeixinConfig getByVerifier(String verifier) {
        return weixinPayConfigDao.getByVerifier(verifier);
    }

    @Override
    public WeixinPayConfig getByAppid(String appId) {
        return weixinPayConfigDao.getByAppid(appId);
    }


    @Override
    public WeixinPayConfig getByPartnerAndAppId(String partner,String appId,Boolean isCache) {
        return cacheService.getByPartnerAndAppId(partner,appId,isCache);
    }

    @Override
    public WeixinPayConfig getByPartner(String mchId) {
        return weixinPayConfigDao.getByPartner(mchId);
    }

    //	@Override
//	public WeixinPayConfig getByPartner(String mchId) {
//		return cacheService.getByPartner(mchId);
//	}
    @Override
    public WeixinPayConfig getByAccountIdPlus(Integer accountId, Integer type, Integer adAccountId) {
        WeixinPayConfig wxPay = cacheService.getWxPay(adAccountId, type);
        if (wxPay == null) {
            wxPay = cacheService.getWxPay(accountId, type);
        }
        return wxPay;
    }

}  